package cn.keniykey.mc.landterritory.toolkit;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 工具包（基础算术类）
 * @author Free-Kingke
 * @version V3.1
 * @修改日期 2019/4/12
 */
public final class ArithmeticUtil {
	private ArithmeticUtil() {}
	/**
	 * 加法算术 [double型]
	 * @param augend 被加数
	 * @param addend 加数
	 * @return 和
	 */
	public static double add(double augend,double addend) {
		BigDecimal Augend = new BigDecimal(String.valueOf(augend));
		BigDecimal Addend = new BigDecimal(String.valueOf(addend));
		return Augend.add(Addend).doubleValue();
	}
	/**
	 * 加法算术 [float型]
	 * @param augend 被加数
	 * @param addend 加数
	 * @return 和
	 */
	public static float add(float augend,float addend) {
		BigDecimal Augend = new BigDecimal(String.valueOf(augend));
		BigDecimal Addend = new BigDecimal(String.valueOf(addend));
		return Augend.add(Addend).floatValue();
	}
	/**
	 * 加法算术
	 * @param augend 被加数
	 * @param addend 加数
	 * @return 和
	 */
	public static BigDecimal add(Number augend,Number addend) {
		BigDecimal Augend = new BigDecimal(String.valueOf(augend));
		BigDecimal Addend = new BigDecimal(String.valueOf(addend));
		return Augend.add(Addend);
	}
	/**
	 * 减法算术 [double型]
	 * @param minuend 被减数
	 * @param reduction 减数
	 * @return 差
	 */
	public static double subtract(double minuend,double reduction) {
		BigDecimal Minuend = new BigDecimal(String.valueOf(minuend));
		BigDecimal Reduction = new BigDecimal(String.valueOf(reduction));
		return Minuend.subtract(Reduction).doubleValue();
	}
	/**
	 * 减法算术 [float型]
	 * @param minuend 被减数
	 * @param reduction 减数
	 * @return 差
	 */
	public static float subtract(float minuend,float reduction) {
		BigDecimal Minuend = new BigDecimal(String.valueOf(minuend));
		BigDecimal Reduction = new BigDecimal(String.valueOf(reduction));
		return Minuend.subtract(Reduction).floatValue();
	}
	/**
	 * 减法算术
	 * @param minuend 被减数
	 * @param reduction 减数
	 * @return 差
	 */
	public static BigDecimal subtract(Number minuend,Number reduction) {
		BigDecimal Minuend = new BigDecimal(String.valueOf(minuend));
		BigDecimal Reduction = new BigDecimal(String.valueOf(reduction));
		return Minuend.subtract(Reduction);
	}
	/**
	 * 乘法算术 [double型]
	 * @param factor 因数
	 * @param factors 因数
	 * @param decimal 小数位
	 * @return 积 
	 */
	public static double multiply(double factor,double factors,int decimal) {
		BigDecimal Factor = new BigDecimal(String.valueOf(factor));
		BigDecimal Factors = new BigDecimal(String.valueOf(factors));
		BigDecimal turn = Factor.multiply(Factors);
		if (decimal >= 0) turn = turn.setScale(decimal, RoundingMode.HALF_UP);
		return turn.doubleValue();
	}
	/**
	 * 乘法算术 [float型]
	 * @param factor 因数
	 * @param factors 因数
	 * @param decimal 小数位
	 * @return 积 
	 */
	public static float multiply(float factor,float factors,int decimal) {
		BigDecimal Factor = new BigDecimal(String.valueOf(factor));
		BigDecimal Factors = new BigDecimal(String.valueOf(factors));
		BigDecimal turn = Factor.multiply(Factors);
		if (decimal >= 0) turn = turn.setScale(decimal, RoundingMode.HALF_UP);
		return turn.floatValue();
	}
	/**
	 * 乘法算术
	 * @param factor 因数
	 * @param factors 因数
	 * @param decimal 小数位
	 * @return 积 
	 */
	public static BigDecimal multiply(Number factor,Number factors,int decimal) {
		BigDecimal Factor = new BigDecimal(String.valueOf(factor));
		BigDecimal Factors = new BigDecimal(String.valueOf(factors));
		BigDecimal turn = Factor.multiply(Factors);
		if (decimal >= 0) turn = turn.setScale(decimal, RoundingMode.HALF_UP);
		return turn;
	}
	/**
	 * 除法算术 [double型]
	 * @param dividend 被除数
	 * @param divisor 除数
	 * @param decimal 小数位
	 * @return 商
	 */
	public static double divide(double dividend,double divisor,int decimal) {
		BigDecimal Dividend = new BigDecimal(String.valueOf(dividend));
		BigDecimal Divisor = new BigDecimal(String.valueOf(divisor));
		final BigDecimal turn = Dividend.divide(Divisor, decimal, RoundingMode.HALF_UP);
		return turn.doubleValue();
	}
	/**
	 * 除法算术 [float型]
	 * @param dividend 被除数
	 * @param divisor 除数
	 * @param decimal 小数位
	 * @return 商
	 */
	public static float divide(float dividend,float divisor,int decimal) {
		BigDecimal Dividend = new BigDecimal(String.valueOf(dividend));
		BigDecimal Divisor = new BigDecimal(String.valueOf(divisor));
		final BigDecimal turn = Dividend.divide(Divisor, decimal, RoundingMode.HALF_UP);
		return turn.floatValue();
	}
	/**
	 * 除法算术
	 * @param dividend 被除数
	 * @param divisor 除数
	 * @param decimal 小数位
	 * @return 商
	 */
	public static BigDecimal divide(Number dividend,Number divisor,int decimal) {
		BigDecimal Dividend = new BigDecimal(String.valueOf(dividend));
		BigDecimal Divisor = new BigDecimal(String.valueOf(divisor));
		final BigDecimal turn = Dividend.divide(Divisor, decimal, RoundingMode.HALF_UP);
		return turn;
	}
}